package com.foreknow.elm.controller;

import com.foreknow.elm.po.Orders;
import com.foreknow.elm.service.OrdersService;
import com.foreknow.elm.service.impl.OrdersServiceImpl;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

public class OrdersController {
    //下订单（先清空当前用户购物车中当前商家的所有食品，然后生成订单和订单明细，最后返回订单号）
    public Object createOrders(HttpServletRequest request) {
        String userId = request.getParameter("userId");
        Integer businessId = Integer.valueOf(request.getParameter("businessId"));
        Integer daId = Integer.valueOf(request.getParameter("daId"));
        Double orderTotal= Double.valueOf(request.getParameter("orderTotal"));
        OrdersService service = new OrdersServiceImpl();
        int orderId = service.createOrders(userId, businessId, daId,orderTotal);
        return orderId;
    }
    public Object getOrdersById(HttpServletRequest request) {
        Integer orderId = Integer.valueOf(request.getParameter("orderId"));
        OrdersService service = new OrdersServiceImpl();
        Orders orders = service.getOrdersById(orderId);
        return orders;
    }
    public Object listOrdersByUserId(HttpServletRequest request){
        String userId = request.getParameter("userId");
        OrdersService service = new OrdersServiceImpl();
        List<Orders> list = service.listOrdersByUserId(userId);
        return list;
    }
}
